unit Thread_FillGrid;

interface

uses
  Classes,BaseGrid,AdvGrid,RzPrgres,SysUtils,StrUtils;

type
  TThreadFillGrid = class(TThread)
  public
    FAdvGrid:TAdvStringGrid;
    FProg   :TRzProgressBar;
  protected
    procedure Execute; override;
  end;

implementation
uses
  Form_Prog;

{ 
  Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);  

  and UpdateCaption could look like,

    procedure FillGrid.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; 
    
    or 
    
    Synchronize( 
      procedure 
      begin
        Form1.Caption := 'Updated in thread via an anonymous method' 
      end
      )
    );
    
  where an anonymous method is passed.
  
  Similarly, the developer can call the Queue method with similar parameters as 
  above, instead passing another TThread class as the first parameter, putting
  the calling thread in a queue with the other thread.
    
}

{ FillGrid }

procedure TThreadFillGrid.Execute;
var
  M,N:Integer;
begin
  with FAdvGrid do
  begin
    //BeginUpdate;
    FProg.TotalParts:=4000;
    for M := 0 to 4000-1  do
    begin
      for N := 0 to ColCount - 1 do
      begin
        Cells[N,M]:=Format('[%D|%D]',[N,M]);
      end;
      Sleep(5);
      FProg.PartsComplete:=M+1;
      FAdvGrid.ScrollInView(0,M+10);
    end;
    //EndUpdate;
  end;
end;

end.
